package org.kca.yarmour.utils;
import java.util.Comparator;

public class Pair <A, B>{

    A a;
    B b;

    public Pair (A aa, B bb)
    {
        a = aa;
        b = bb;
    }
    public A getA()
    {
        return a;
    }

    public B getB()
    {
        return b;
    }

    public void setA(A aa)
    {
        a = aa;
    }

    public void setB(B bb)
    {
        b = bb;
    }

    @SuppressWarnings("unchecked")
    @Override
    public boolean equals(Object o)
    {
        if (!(o instanceof Pair<?, ?>)) return false;
        Pair<A, B> pair = (Pair<A, B>) o;
        return a.equals(pair.a) && b.equals(pair.b);
    }

    public String toString()
    {
        return "{" + a.toString() + "," + b.toString() + "}";
    }

    public static <A extends Comparable<A>, B> Comparator<Pair<A, B>> getAComparator()
    {
        return new Comparator<Pair<A, B>>()
        {
            public int compare(Pair<A, B> pair1, Pair<A, B> pair2)
            {
                return pair1.a.compareTo(pair2.a);
            }
        };
    }

    public static <A, B extends Comparable<B>> Comparator<Pair<A, B>> getBComparator()
    {
        return new Comparator<Pair<A, B>>()
        {
            public int compare(Pair<A, B> pair1, Pair<A, B> pair2)
            {
                return pair1.b.compareTo(pair2.b);
            }
        };
    }

    public static class IntPair extends Pair<Integer, Integer>
    {
        public IntPair(Integer aa, Integer bb)
        {
            super(aa, bb);
        }
    }
}
